package com.example.controller;


import com.example.dto.BookCopyAddDTO;
import com.example.dto.BookCopyUpdateDTO;
import com.example.service.BookCopyService;
import com.example.util.Result;
import com.example.vo.BookCopyWithDetailsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 图书副本管理控制器
 */
@RestController
@RequestMapping("/api/book-copy")
@Tag(name = "图书副本管理", description = "图书副本相关接口")
public class BookCopyController {

    @Autowired
    private BookCopyService bookCopyService;

    @PostMapping("/add")
    @Operation(summary = "添加图书副本")
    public Result addBookCopy(@RequestBody @Valid BookCopyAddDTO bookCopyAddDTO) {
        return bookCopyService.addBookCopy(bookCopyAddDTO);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取图书副本详情")
    public Result getBookCopyById(@PathVariable Long id) {
        return bookCopyService.getBookCopyById(id);
    }

    @GetMapping("/book/{bookId}")
    @Operation(summary = "根据图书ID获取所有副本")
    public Result getBookCopiesByBookId(@PathVariable Long bookId) {
        return bookCopyService.getBookCopiesByBookId(bookId);
    }

    @GetMapping("/available/{bookId}")
    @Operation(summary = "获取指定图书的可借阅副本")
    public Result getAvailableBookCopies(@PathVariable Long bookId) {
        return bookCopyService.getAvailableBookCopies(bookId);
    }

    @PostMapping("/delete")
    @Operation(summary = "删除图书副本")
    public Result deleteBookCopy(@RequestParam Long id) {
        return bookCopyService.deleteBookCopy(id);
    }
}